home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWBTxtSh.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.7 KB  |  187 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBTxtSh.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWBTXTSH_H
  13. #include "FWBTxtSh.h"
  14. #endif
  15.  
  16. //========================================================================================
  17. //    RunTime Info
  18. //========================================================================================
  19.  
  20. #ifdef FW_BUILD_MAC
  21. #pragma segment fwgraphxshape
  22. #endif
  23.  
  24. FW_DEFINE_CLASS_M1(FW_CBaseTextShape, FW_CShape)
  25. FW_DEFINE_AUTO(FW_CBaseTextShape)
  26.  
  27. //========================================================================================
  28. //    class FW_CBaseTextShape
  29. //========================================================================================
  30.  
  31. //----------------------------------------------------------------------------------------
  32. //    FW_CBaseTextShape::FW_CBaseTextShape
  33. //----------------------------------------------------------------------------------------
  34.  
  35. FW_CBaseTextShape::FW_CBaseTextShape(const FW_CBaseTextShape& other) :
  36.     FW_CShape(other),
  37.     fString(other.fString)
  38. {
  39.     FW_END_CONSTRUCTOR
  40. }
  41.  
  42. //----------------------------------------------------------------------------------------
  43. //    FW_CBaseTextShape::FW_CBaseTextShape
  44. //----------------------------------------------------------------------------------------
  45.  
  46. FW_CBaseTextShape::FW_CBaseTextShape(const FW_CString& string,
  47.                                        const FW_CInk& ink,
  48.                                      const FW_CFont& font) :
  49.     FW_CShape(FW_kFill, ink, FW_kNormalStyle, font),
  50.     fString(string)
  51. {    
  52.     FW_END_CONSTRUCTOR
  53. }
  54.  
  55. //----------------------------------------------------------------------------------------
  56. //    FW_CBaseTextShape::FW_CBaseTextShape
  57. //----------------------------------------------------------------------------------------
  58.  
  59. FW_CBaseTextShape::FW_CBaseTextShape() :
  60.     FW_CShape(FW_kFill, FW_kOr, FW_kNormalStyle, FW_kNormalFont)
  61. {            
  62.     FW_END_CONSTRUCTOR
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    FW_CBaseTextShape::FW_CBaseTextShape
  67. //----------------------------------------------------------------------------------------
  68.  
  69. FW_CBaseTextShape::FW_CBaseTextShape(FW_CTextReader& textReader,
  70.                                        const FW_CInk& ink,
  71.                                      const FW_CFont& font) :
  72.     FW_CShape(FW_kFill, ink, FW_kNormalStyle, font)
  73. {    
  74.     SetText(textReader);
  75.     
  76.     FW_END_CONSTRUCTOR
  77. }
  78.  
  79. //----------------------------------------------------------------------------------------
  80. //    FW_CBaseTextShape::FW_CBaseTextShape
  81. //----------------------------------------------------------------------------------------
  82.  
  83. FW_CBaseTextShape::FW_CBaseTextShape(FW_CReadableStream& stream) :
  84.     FW_CShape(stream)
  85. {
  86.     stream >> fString;
  87.     FW_END_CONSTRUCTOR
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_CBaseTextShape::~FW_CBaseTextShape
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_CBaseTextShape::~FW_CBaseTextShape()
  95. {
  96.     FW_START_DESTRUCTOR
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    FW_CBaseTextShape::operator=
  101. //----------------------------------------------------------------------------------------
  102.  
  103. FW_CBaseTextShape& FW_CBaseTextShape::operator=(const FW_CBaseTextShape& other)
  104. {
  105.     if (this != &other)
  106.     {
  107.         FW_CShape::operator=(other);
  108.         // MetroWerks bug workaround [AMB]
  109.         FW_CString& string = fString;    
  110.         string = other.fString;
  111.     }
  112.     
  113.     return *this;
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CBaseTextShape::Flatten
  118. //----------------------------------------------------------------------------------------
  119.  
  120. void FW_CBaseTextShape::Flatten(FW_CWritableStream& stream) const
  121. {
  122.     FW_CShape::Flatten(stream);
  123.     stream << fString;
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    FW_CBaseTextShape::HitTest
  128. //----------------------------------------------------------------------------------------
  129.  
  130. FW_Boolean FW_CBaseTextShape::HitTest(FW_CGraphicContext& gc,
  131.                                       const FW_CPoint& test,
  132.                                       FW_Fixed tolerance) const
  133. {
  134.     FW_CRect bounds;
  135.     GetBounds(gc, bounds);
  136.     
  137.     bounds.Inset(-tolerance, -tolerance);
  138.  
  139.     return bounds.Contains(test);
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CBaseTextShape::GetText
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CBaseTextShape::GetText(FW_CTextWriter& textWriter) const
  147. {
  148.     // MetroWerks bug workaround [AMB]
  149.     const FW_CString& string = fString;    
  150.  
  151.     // Write string's characters to textWriter's data structure
  152.     FW_CStringReader stringReader(string);
  153.     FW_ByteCount len = stringReader.GetByteLength();
  154.     FW_LChar ch;
  155.  
  156.     for (short i=0; i < len; i++)
  157.     {
  158.         ch = stringReader.GetCharacterAndAdvance();
  159.         textWriter.PutCharacterAndAdvance(ch);
  160.     }
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CBaseTextShape::SetText
  165. //----------------------------------------------------------------------------------------
  166.  
  167. void FW_CBaseTextShape::SetText(FW_CTextReader& textReader)
  168. {
  169.     const char* start;
  170.     FW_ByteCount length;
  171.  
  172.     // MetroWerks bug workaround [AMB]
  173.     FW_CString& string = fString;    
  174.     string.Truncate(0);                                        // empty the string
  175.     do
  176.     {
  177.         textReader.PeekRunAhead(start, length);                // get address and length of buffer
  178.         if (length > 0)
  179.         {
  180.             string.Append(start, length);                    // append buffer chars to string
  181.             textReader.Advance(length);                        // advance to next buffer of chars, if any
  182.         }
  183.     }
  184.     while (length > 0);
  185. }
  186.  
  187.